home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / RCShaders / RCShowXYZ.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  764 b   |  32 lines

  1. /* Listing 16.13  Shader mapping shader-space coordinates to colors*/
  2. /* 
  3.  * show_xyz(): Color a surface point according to its xyz coordinates 
  4.  *     within a bounding box.
  5.  */
  6.  
  7. surface 
  8. RCShowXYZ( 
  9.     float    xmin    = -1, 
  10.         ymin    = -1, 
  11.         zmin    = -1,
  12.          xmax    =  1, 
  13.         ymax    =  1,
  14.         zmax    =  1 )
  15. {
  16.     uniform point scale, zero;
  17.     point objP, cubeP;
  18.  
  19.     /* Check for zero scale components. */
  20.     if(xmax==xmin || ymax==ymin || zmax==zmin) {
  21.         printf( "bad bounding box %f %f %f %f %f %f in show_xyz()",
  22.                 xmin, xmax, ymin, ymax, zmin, zmax );
  23.     } else {
  24.         scale = point (1/(xmax-xmin), 1/(ymax-ymin), 1/(zmax-zmin));
  25.         zero = point (xmin, ymin, zmin);
  26.  
  27.         objP = transform("shader", P);
  28.         cubeP = (objP - zero) * scale;
  29.         Ci = color (xcomp(cubeP), ycomp(cubeP), zcomp(cubeP));
  30.     }
  31. }
  32.